package mini.statement;


import java.util.HashMap;
import java.util.LinkedList;

import mini.ParamList;
import mini.Proc;
import mini.StatementList;

public class DefineStatement extends Statement {

    private String name;
    private Proc proc;

    public DefineStatement(String id, Proc process) {
        name = id;
        proc = process;
    }

    @Override
    public void eval(HashMap<String, Integer> nametable, HashMap<String, Proc> functable, LinkedList var) {
        // get the named proc object from the function table.
        //System.out.println("Adding Process:"+name+" to Functiontable");
        functable.put(proc.getLocationLabel(), proc);
    }
    
    /**
     * Definitions of functions don't actually add to the code; they just add the function
     * to the function table
     * 
     * @return An empty string (not null!) to append, because we're just putting stuff in the functable for now
     */
    public String parse(HashMap<String, Integer> nametable, HashMap<String, Proc> functable, LinkedList var) {
    	
    	// A difference is that we need to parse it, to make sure the code is properly generated
    	proc.parse( nametable, functable, var );
    	
    	// And then keep track of it
    	functable.put(name, proc);
    	return "";
    }

}
